package cn.thornbird.orgsync.config;

import cn.thornbird.orgsync.util.WebUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@ControllerAdvice(value = {"cn.thornbird.orgsync.controller.export"})
@Order(Ordered.HIGHEST_PRECEDENCE)
@Slf4j
public class ExportExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public void errorHandler(HttpServletResponse response, Exception exception) throws IOException {
        log.error("error", exception);
        WebUtil.writeExcelErrorMessageToResponse(response, exception.getMessage());
    }

}
